import time
from unittest import TestCase
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from page_object.basepage import BasePage
from comment.get_data import getData
# from logging

class Login(BasePage):
    def login(self):
        ele_data = getData()
        self.driver.find_element(By.CSS_SELECTOR, ele_data[1][2]).clear()
        self.driver.find_element(By.CSS_SELECTOR, ele_data[1][2]).send_keys(ele_data[1][0])
        self.driver.find_element(By.CSS_SELECTOR, ele_data[2][2]).clear()
        self.driver.find_element(By.CSS_SELECTOR, ele_data[2][2]).send_keys(ele_data[1][1])
        """"
            以下步骤是滑动解锁过程
        """
        """滑动解锁"""
        ele_start = self.driver.find_element(By.CSS_SELECTOR, "#box > div.slider")
        """ 激活鼠标 """
        action = ActionChains(self.driver)
        """ 按住鼠标不放"""
        action.click_and_hold(ele_start).perform()
        """ 拖拽400个像素"""
        action.drag_and_drop_by_offset(ele_start, 400, 0).perform()
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, ele_data[4][2]).click()
        """ 获取title """
        title = self.driver.title
        """ 获取用户名 """
        text = self.driver.find_element(By.CSS_SELECTOR,ele_data[5][2]).text

        time.sleep(3)
        # self.driver.quit()
        self.driver.find_element(By.LINK_TEXT, "退出").click()
        return  title, text
if __name__ == "__main__":
    from selenium import webdriver
    driver = webdriver.Firefox()
    driver.get("http://javaweb.aroundme.tv:8083/Testhuaxi/login.jsp")
    login_ = Login(driver)
    login_.login()


